package ee.ut.maxorato_macobo.oop.mud.game;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.TreeMap;

public class NpcPool {
	private static TreeMap<Long, NpcCharacter> npcList = new TreeMap<Long, NpcCharacter>();
	
	public static boolean registerNpc(NpcCharacter npc) {
		if(npcList.containsKey(npc.getIndex())) return false;
		
		npcList.put(npc.getIndex(), npc);
		return true;
	}
	
	public static boolean unregisterNpc(NpcCharacter npc) {
		if(!npcList.containsKey(npc.getIndex())) return false;
		
		npcList.remove(npc.getIndex());
		return true;
	}
	
	public static void processTick() {
		Iterator<Entry<Long, NpcCharacter>> it = npcList.entrySet().iterator();
		
		while(it.hasNext()) {
			Entry<Long, NpcCharacter> entry = it.next();
			
			entry.getValue().processTick();
		}
	}
	
	public static void doFightTick() {
		Iterator<NpcCharacter> it = getNpcList().values().iterator();
		
		while(it.hasNext()) {
			it.next().processFightTick();
		}
	}
	
	public static TreeMap<Long, NpcCharacter> getNpcList() {
		return npcList;
	}
	
	private NpcPool() {
		
	}
}
